/*
 * app_pwm.c
 *
 *  Created on: 2023年9月1日
 *      Author: zlw
 */
#include "app_pwm.h"
#include "app_log.h"
#include "app_api.h"
#include "device_type.h"
#ifdef SM_KP
#include "app_led.h"
#endif
#if defined(SM_SOUND) || defined(SM_OUTSOUND)
#define BEEP_RESONANCE_FREQUENCY  1400 //单位HZ 室内警号
#else
#define BEEP_RESONANCE_FREQUENCY  2700 //单位HZ 室内警号
#endif

#define LIGHT_DEFAULT_DUTY   99 //表示亮度

typedef enum
{
  PWM_SOUND_LIGHT_CTRL_STATE_IDLE,
  PWM_SOUND_LIGHT_CTRL_STATE_HOLD_ON,
  PWM_SOUND_LIGHT_CTRL_STATE_HOLD_OFF,
  PWM_SOUND_LIGHT_CTRL_STATE_FREQ_RAISE_CHANGE,
  /*
  PWM_SOUND_LIGHT_CTRL_STATE_FREQ_RAISE_UP,
  PWM_SOUND_LIGHT_CTRL_STATE_FREQ_RAISE_DOWN,
  PWM_SOUND_LIGHT_CTRL_STATE_FREQ_HOLD_UP,
  PWM_SOUND_LIGHT_CTRL_STATE_FREQ_HOLD_DOWN,
  */
  PWM_SOUND_LIGHT_CTRL_STATE_ABORT //中止
}PWM_SOUND_LIGHT_CTRL_STATE_E;

typedef enum
{
  PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_NONE,
  PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_SOUNDLIGHT,
  PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_BLINK
}PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_E;

typedef struct
{
  SOUND_LIGHT_OUT_TYPE_E eSoundLightTypeEvent;
  SOUND_LIGHT_OUT_TYPE_E eSoundLightLastTypeEvent;
  bool                    isSoundOn;
  bool                    isSoundLastOn;
  bool                    isLightOn;
  bool                    isLightLastOn;
  uint16_t                lowFreq ;
  uint16_t                highFreq;
  uint16_t                upStepF;
  uint16_t                downStepF;

  SOUND_BLINK_TYPE_E     eBlinkTypeEvent;
  bool                    isBlinkSoundOn;
  bool                    isBlinkLightOn;
  uint8_t                byBlinkDownCount;

  uint8_t                volumeDuty;

  PWM_SOUND_LIGHT_CTRL_STATE_E      eCurrentState;
  PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_E eHandlingEvent;

  MultiTimer                        stDelayTimer;
  bool                              isTimeExpired;

}SOUND_LIGHT_CTRL_BLOCK_ST;


const uint8_t soundVolumeDuty[SOUND_VOLUME_CLASS_NUM] = {94,86,40};//{94,82,20};

static SOUND_LIGHT_CTRL_BLOCK_ST s_soundLightCtrlBlock ={
    .eSoundLightTypeEvent = SOUND_LIGHT_OUT_TYPE_OFF,
    .eSoundLightLastTypeEvent = SOUND_LIGHT_OUT_TYPE_OFF,
    .isSoundLastOn = false,
    .isLightLastOn = false,
    .eBlinkTypeEvent = SOUND_BLINK_TYPE_OFF,
    .volumeDuty = soundVolumeDuty[SOUND_VOLUME_CLASS_MEDIUM],
    .eCurrentState= PWM_SOUND_LIGHT_CTRL_STATE_IDLE,
    .eHandlingEvent = PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_NONE
};

#define FREQ_RAISE_CHANGE_TIME  164//1/32768 328/2 5ms变化一次
static MultiTimer freqRaiseChangeTimer ={.Handle = 2023};
static uint16_t   s_nowFreq;
static bool       s_isFreqRaise = true; //是否频率缓慢升高或降低
static bool       s_isLightSyncFreq = true;
static uint16_t   s_ligthChangeUpCnt =  0;
static uint32_t   s_freqChangeTime = FREQ_RAISE_CHANGE_TIME;

static void pwm_duty_off(pwm_device_t device)
{
  if(beeppwm == device)
  {
    SM_beep_disable();
  }
   pwm_duty_set(device, 0);//两者均为0电平无效
#ifdef SM_KP
  if(ledpwm == device){
      if(s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_OPTION_FAIL || s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_KEYPAD_LOCK) {
          keyPad_led_off(BACK_LIGHT);
      }
      else if(s_soundLightCtrlBlock.eBlinkTypeEvent != SOUND_BLINK_TYPE_OFF){
          keyPad_led_off(DEPLOY_GREEN);
      }
  }
#endif
}

static void pwm_duty_on(pwm_device_t device, uint8_t duty )
{
  if(duty >= 100){
    return;
  }
  if(beeppwm == device)
  {
    SM_beep_enable();
  }
  pwm_duty_set(device, duty);
#ifdef SM_KP
  if(ledpwm == device){
      if(s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_OPTION_FAIL || s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_KEYPAD_LOCK) {
          keyPad_led_on(BACK_LIGHT);
      }
      else if(s_soundLightCtrlBlock.eBlinkTypeEvent != SOUND_BLINK_TYPE_OFF){
          keyPad_led_on(DEPLOY_GREEN);
      }
  }
#endif
}

static void pwm_freq_set(uint16_t frequency)
{
  pwm_frequency_set(frequency);
  s_nowFreq = frequency;
}

static void delayTimerCallback(struct MultiTimerHandle* timeHandle,void* pData)
{

  (void) timeHandle;
  (void) pData;
  s_soundLightCtrlBlock.isTimeExpired = true;
}

static bool s_isFreqRaiseChanged = false;

static void freqRaiseChangeTimerCallback(struct MultiTimerHandle* timeHandle,void* pData)
{

  (void) timeHandle;
  (void) pData;
  s_isFreqRaiseChanged = true;
  if(s_soundLightCtrlBlock.isSoundOn && s_isFreqRaise)//声音打开 且非医疗报警，医疗无需缓升频率，无需缓降频率
    pwm_freq_set(s_nowFreq);
  softwareMultiTimerStart(EN_LP_HARD_TIMER_EM3_SYS_RTC_1,&freqRaiseChangeTimer,s_freqChangeTime,freqRaiseChangeTimerCallback,NULL,0);
}

static void freqRaiseChangePreset()
{
  static bool isUp = true;
  if(s_nowFreq <= s_soundLightCtrlBlock.lowFreq )
  {
    if(s_soundLightCtrlBlock.isLightOn && s_isLightSyncFreq)
        pwm_duty_on(ledpwm,LIGHT_DEFAULT_DUTY);

    if(s_soundLightCtrlBlock.isSoundOn && (!s_isFreqRaise) && (!isUp))
      pwm_freq_set(s_soundLightCtrlBlock.lowFreq);

    isUp = true;//升频

  }
  else if(s_nowFreq >= s_soundLightCtrlBlock.highFreq)
  {
    if(s_soundLightCtrlBlock.isLightOn && s_isLightSyncFreq)
        pwm_duty_off(ledpwm);

    if(s_soundLightCtrlBlock.isSoundOn && (!s_isFreqRaise) && (isUp))
      pwm_freq_set(s_soundLightCtrlBlock.highFreq);

    isUp = false;//降频
  }

  //灯亮灭 不跟随频率变化 ，固定500ms/500ms
  if(s_soundLightCtrlBlock.isLightOn && !s_isLightSyncFreq)
    {
      s_ligthChangeUpCnt ++;

      if(s_ligthChangeUpCnt == 1)
        {
          pwm_duty_on(ledpwm,LIGHT_DEFAULT_DUTY);
        }
      else if(s_ligthChangeUpCnt == 100) //500ms时间
        {
          pwm_duty_off(ledpwm);
        }
      else if(s_ligthChangeUpCnt == 200) {
          s_ligthChangeUpCnt = 0;
      }
    }

  if(isUp)
  {
    s_nowFreq += s_soundLightCtrlBlock.upStepF;
    if(s_soundLightCtrlBlock.isSoundOn)
      pwm_frequency_preset(s_nowFreq);
    else
      pwm_duty_off(beeppwm);
  }
  else
  {
    s_nowFreq -= s_soundLightCtrlBlock.downStepF;
    if(s_soundLightCtrlBlock.isSoundOn)
      pwm_frequency_preset(s_nowFreq);
    else
      pwm_duty_off(beeppwm);
  }
}
#ifdef SM_KP
extern uint8_t s_option_index_value_get(uint8_t index);
#endif
void pwm_soundLight_start(SOUND_LIGHT_OUT_TYPE_E eType,bool isSoundOn ,bool isLightOn)//指持续的音效,isLightOn 与 isSoundOn 不能同时为false
{
  s_soundLightCtrlBlock.isSoundOn = isSoundOn;
  s_soundLightCtrlBlock.isLightOn = isLightOn;
#ifdef SM_KP
  uint8_t option2 = s_option_index_value_get(2);
  if(((option2 >> 1)&0x01) && isSoundOn == true) {
      s_soundLightCtrlBlock.isSoundOn = false;
      if(isLightOn == false) {
          return ;
      }
  }
#endif
  s_soundLightCtrlBlock.eSoundLightTypeEvent = eType;

  if(s_soundLightCtrlBlock.eSoundLightLastTypeEvent != s_soundLightCtrlBlock.eSoundLightTypeEvent
      || s_soundLightCtrlBlock.isSoundLastOn != s_soundLightCtrlBlock.isSoundOn
      || s_soundLightCtrlBlock.isLightLastOn != s_soundLightCtrlBlock.isLightOn){
      if(s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_OFF) {
          s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_ABORT; //终止当前状态
      }
      s_soundLightCtrlBlock.eSoundLightLastTypeEvent = s_soundLightCtrlBlock.eSoundLightTypeEvent;
      s_soundLightCtrlBlock.isSoundLastOn = s_soundLightCtrlBlock.isSoundOn;
      s_soundLightCtrlBlock.isLightLastOn = s_soundLightCtrlBlock.isLightOn;
  }
}
void pwm_blink_start(SOUND_BLINK_TYPE_E eType,uint8_t times, bool isSoundOn, bool isLightOn) //特指滴滴的音效，times指次数，可打断soundLightisLightOn 与 isSoundOn 不能同时为false
{
  s_soundLightCtrlBlock.isBlinkSoundOn = isSoundOn;
  s_soundLightCtrlBlock.isBlinkLightOn = isLightOn;
#ifdef SM_KP
  uint8_t option2 = s_option_index_value_get(2);
  if(((option2 >> 1)&0x01) && isSoundOn == true) {
      s_soundLightCtrlBlock.isBlinkSoundOn = false;
      if(isLightOn == false) {
          return ;
      }
  }
#endif
  s_soundLightCtrlBlock.eBlinkTypeEvent = eType;
  s_soundLightCtrlBlock.byBlinkDownCount = times;

  if(s_soundLightCtrlBlock.eCurrentState != PWM_SOUND_LIGHT_CTRL_STATE_IDLE) {
      s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_ABORT; //终止当前状态
#ifdef SM_KP
  if(isLightOn == false && (eType == SOUND_BLINK_TYPE_KEY_PRESS || eType == SOUND_BLINK_TYPE_OPERATION_TIPS)) {
      keyPad_led_on(BACK_LIGHT);
  }
#endif
  }
}

void pwm_sound_volume_set(SOUND_VOLUME_CLASS_E eClass)//指持续的音效
{
   s_soundLightCtrlBlock.volumeDuty = soundVolumeDuty[eClass];
   pwm_duty_value_set(s_soundLightCtrlBlock.volumeDuty);//将duty值传递给底层PWM驱动
}

//return delay time
static uint32_t  holdOffStateEntry(SOUND_BLINK_TYPE_E type )
{
  uint32_t delayTime = 5*3276; //5*100ms

  if(freqRaiseChangeTimer.status != EN_MULTITIMER_STATUS_IDLE){
     softwareMultiTimerStop(EN_LP_HARD_TIMER_EM3_SYS_RTC_1,&freqRaiseChangeTimer,0);
  }

  pwm_duty_off(beeppwm);
  pwm_duty_off(ledpwm);
  pwm_stop();

  switch (type)
  {
    case SOUND_BLINK_TYPE_KEY_PRESS:
      delayTime = 3276;
      break;
    case SOUND_BLINK_TYPE_OPERATION_TIPS:
      delayTime = 5*3276;
      break;
    case SOUND_BLINK_TYPE_OPTION_FAIL:
      delayTime = 2*3276;
      break;
    case SOUND_BLINK_TYPE_KEYPAD_LOCK:
      delayTime = 5*3276;
      break;
    default:
      break;
  }

  return delayTime;
}

static uint32_t  holdOnStateEntry(SOUND_BLINK_TYPE_E type )
{
  uint32_t delayTime = 5*3276;
  uint32_t freq = BEEP_RESONANCE_FREQUENCY;

  switch (type)
  {
    case SOUND_BLINK_TYPE_KEY_PRESS:
      delayTime = 3276; //100ms
      break;
    case SOUND_BLINK_TYPE_OPERATION_TIPS:
      delayTime = 5*3276; //5*100ms
      break;
    case SOUND_BLINK_TYPE_OPTION_FAIL:
      delayTime = 2*3276;
      break;
    case SOUND_BLINK_TYPE_KEYPAD_LOCK:
      delayTime = 5*3276;
      break;
    default :
      break;
  }

  if(s_soundLightCtrlBlock.isBlinkSoundOn){
      pwm_duty_on(beeppwm,s_soundLightCtrlBlock.volumeDuty);
    }
  else{
      pwm_duty_off(beeppwm);
  }

  if(s_soundLightCtrlBlock.isBlinkLightOn){
      pwm_duty_on(ledpwm,LIGHT_DEFAULT_DUTY);
    }
  else{
      pwm_duty_off(ledpwm);
  }

  pwm_freq_set(freq);
  pwm_start(); //开始PWM输出
  return delayTime;
}

static void  freqRaiseChangeUpStateEntry(SOUND_LIGHT_OUT_TYPE_E type )
{
  s_freqChangeTime = FREQ_RAISE_CHANGE_TIME; //默认宏5ms
  s_isFreqRaise = true; //使能缓慢升高或降低频率
  s_isLightSyncFreq = true;//默认 灯光与频率变化同步，升频亮灯，降频灭灯，同步声光
  switch(type)
  {
    case SOUND_LIGHT_OUT_TYPE_OFF:
      printf("[ERROR] freq up OFF\r\n");
    break;

    case SOUND_LIGHT_OUT_TYPE_INTRUSION_ALARM: //入侵报警
      s_soundLightCtrlBlock.lowFreq = 1400;
      s_soundLightCtrlBlock.highFreq = 2200;
      s_soundLightCtrlBlock.upStepF = 20;//(s_soundLightCtrlBlock.highFreq - s_soundLightCtrlBlock.lowFreq) / s_soundLightCtrlBlock.upStepF * FREQ_RAISE_CHANGE_TIME;
      s_soundLightCtrlBlock.downStepF = 100;
      break;

    case SOUND_LIGHT_OUT_TYPE_FIRE: //火警 119
      s_soundLightCtrlBlock.lowFreq =  1400;
      s_soundLightCtrlBlock.highFreq = 3000;
      s_soundLightCtrlBlock.upStepF = 7;//(s_soundLightCtrlBlock.highFreq - s_soundLightCtrlBlock.lowFreq) / s_soundLightCtrlBlock.upStepF * FREQ_RAISE_CHANGE_TIME;
      s_soundLightCtrlBlock.downStepF = 3;
      s_isLightSyncFreq = false;//火警灯效单独控制
      s_ligthChangeUpCnt = 0;
    break;

    case SOUND_LIGHT_OUT_TYPE_SOS: //紧急求助 110,
      s_soundLightCtrlBlock.lowFreq =  1400;
      s_soundLightCtrlBlock.highFreq = 2320;
      s_soundLightCtrlBlock.upStepF = 20;//(s_soundLightCtrlBlock.highFreq - s_soundLightCtrlBlock.lowFreq) / s_soundLightCtrlBlock.upStepF * FREQ_RAISE_CHANGE_TIME;
      s_soundLightCtrlBlock.downStepF = 46;
    break;

    case SOUND_LIGHT_OUT_TYPE_MEDICAL: //医疗,ToDo
      s_soundLightCtrlBlock.lowFreq =  1400;
      s_soundLightCtrlBlock.highFreq = 1880;
      s_soundLightCtrlBlock.upStepF = 6;//(s_soundLightCtrlBlock.highFreq - s_soundLightCtrlBlock.lowFreq) / s_soundLightCtrlBlock.upStepF * FREQ_RAISE_CHANGE_TIME;
      s_soundLightCtrlBlock.downStepF = 4;
      s_isFreqRaise = false;//不缓慢升高
    break;
  }

  //设置duty
  if(s_soundLightCtrlBlock.isSoundOn){
      pwm_duty_on(beeppwm,s_soundLightCtrlBlock.volumeDuty);
    }
  else{
      pwm_duty_off(beeppwm);
  }

  if(s_soundLightCtrlBlock.isLightOn){
      pwm_duty_on(ledpwm,LIGHT_DEFAULT_DUTY);
    }
  else{
      pwm_duty_off(ledpwm);
  }

  pwm_freq_set(s_soundLightCtrlBlock.lowFreq);
  s_isFreqRaiseChanged = true;
  pwm_start(); //开始PWM输出

  if(freqRaiseChangeTimer.status == EN_MULTITIMER_STATUS_IDLE)
    softwareMultiTimerStart(EN_LP_HARD_TIMER_EM3_SYS_RTC_1,&freqRaiseChangeTimer,s_freqChangeTime,freqRaiseChangeTimerCallback,NULL,1);
}

void pwm_sound_light_stateMachine_run()
{
  bool isLoop = false;
  uint32_t delayTime = 0; //0 表示无需计时定时
  static PWM_SOUND_LIGHT_CTRL_STATE_E lastState = PWM_SOUND_LIGHT_CTRL_STATE_IDLE;
  do
    {
      isLoop = false;
      switch(s_soundLightCtrlBlock.eCurrentState)
      {
        case PWM_SOUND_LIGHT_CTRL_STATE_IDLE:
          //先处理滴滴事件
          if(s_soundLightCtrlBlock.eBlinkTypeEvent != SOUND_BLINK_TYPE_OFF)
            {
              if(s_soundLightCtrlBlock.eHandlingEvent == PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_SOUNDLIGHT
                  || s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_OPTION_FAIL
                  || s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_KEYPAD_LOCK){
                s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_HOLD_OFF; //若前面已经在持续声音输出，则间隔一段时间再滴滴
                holdOffStateEntry(s_soundLightCtrlBlock.eBlinkTypeEvent);
                delayTime = 3276; //100ms
              }
              else{
                s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_HOLD_ON;
                delayTime = holdOnStateEntry(s_soundLightCtrlBlock.eBlinkTypeEvent);
              }

              s_soundLightCtrlBlock.eHandlingEvent = PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_BLINK;
            }

          //再处理 持续声光输出事件
          else if(s_soundLightCtrlBlock.eSoundLightTypeEvent != SOUND_LIGHT_OUT_TYPE_OFF)
            {
              s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_FREQ_RAISE_CHANGE;
              freqRaiseChangeUpStateEntry(s_soundLightCtrlBlock.eSoundLightTypeEvent);
              s_soundLightCtrlBlock.eHandlingEvent = PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_SOUNDLIGHT;
            }

          //无事件，清空
          else
            {
              s_soundLightCtrlBlock.eHandlingEvent = PWM_SOUND_LIGHT_CTRL_EVENT_TYPE_NONE;
            }
          break;
        case PWM_SOUND_LIGHT_CTRL_STATE_HOLD_ON:
          if(s_soundLightCtrlBlock.isTimeExpired)
            {
              s_soundLightCtrlBlock.isTimeExpired = false;
              s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_HOLD_OFF;
              holdOffStateEntry(s_soundLightCtrlBlock.eBlinkTypeEvent);
              if(s_soundLightCtrlBlock.byBlinkDownCount > 0) {
                  s_soundLightCtrlBlock.byBlinkDownCount --;
              } else {
                  DS_app_log_error("blink cnt toggle \r\n");
              }

              if(s_soundLightCtrlBlock.byBlinkDownCount > 0){
                 delayTime = holdOffStateEntry(s_soundLightCtrlBlock.eBlinkTypeEvent);
              }
              //若为最后1次，则仅delay 10ms
              else{
                  delayTime = 3277; //10ms
              }
            }

          break;
        case PWM_SOUND_LIGHT_CTRL_STATE_HOLD_OFF:
          if(s_soundLightCtrlBlock.isTimeExpired)
            {
              s_soundLightCtrlBlock.isTimeExpired = false;
              if(s_soundLightCtrlBlock.byBlinkDownCount > 0)
              {
                  s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_HOLD_ON;
                  delayTime = holdOnStateEntry(s_soundLightCtrlBlock.eBlinkTypeEvent);
              }
              else
              {
#ifdef SM_KP
                  if(s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_OPTION_FAIL) {
                      keyPad_led_on(BACK_LIGHT);
                  }
#endif
                  s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_IDLE; //执行完成，清除事件 并直接Idle，不用再打开
                  s_soundLightCtrlBlock.eBlinkTypeEvent = SOUND_BLINK_TYPE_OFF;
                  isLoop = true;
              }
            }

          break;
        case PWM_SOUND_LIGHT_CTRL_STATE_FREQ_RAISE_CHANGE:

          if(s_isFreqRaiseChanged)
          {
            s_isFreqRaiseChanged = false;
            freqRaiseChangePreset();
          }

          //若事件关闭，则调该指令
          if(s_soundLightCtrlBlock.eSoundLightTypeEvent == SOUND_LIGHT_OUT_TYPE_OFF)
            {
              s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_IDLE;
              holdOffStateEntry(SOUND_BLINK_TYPE_OFF);
            }

          break;

        case PWM_SOUND_LIGHT_CTRL_STATE_ABORT:
          s_soundLightCtrlBlock.eCurrentState = PWM_SOUND_LIGHT_CTRL_STATE_IDLE;
          holdOffStateEntry(SOUND_BLINK_TYPE_OFF);
          softwareMultiTimerStop(EN_LP_HARD_TIMER_EM3_SYS_RTC_1,&(s_soundLightCtrlBlock.stDelayTimer),0);
          s_soundLightCtrlBlock.isTimeExpired = false;
          isLoop = true;
          break;
      }

      if(lastState!= s_soundLightCtrlBlock.eCurrentState)
        {
          lastState = s_soundLightCtrlBlock.eCurrentState;
          printf("Ps%d\r\n",s_soundLightCtrlBlock.eCurrentState);
        }

    }while(isLoop);

    if(delayTime != 0)
    {
      s_soundLightCtrlBlock.isTimeExpired = false;
      softwareMultiTimerStart(EN_LP_HARD_TIMER_EM3_SYS_RTC_1, &(s_soundLightCtrlBlock.stDelayTimer), delayTime , delayTimerCallback, NULL, 1);
    }
}

bool getPwmIdleState(void)
{
  if(s_soundLightCtrlBlock.eCurrentState == PWM_SOUND_LIGHT_CTRL_STATE_IDLE
     && s_soundLightCtrlBlock.eSoundLightTypeEvent == SOUND_LIGHT_OUT_TYPE_OFF
     && s_soundLightCtrlBlock.eBlinkTypeEvent == SOUND_BLINK_TYPE_OFF) {
      return true;
  }
  else
    return false;
}


__WEAK void SM_beep_enable(void)
{

}

__WEAK void SM_beep_disable(void)
{

}
